﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;

namespace QYmall.Core.Model.ViewModels
{
    /// <summary>
    /// 商户信息(列表)
    /// </summary>
    public class MerchantsDto: MerchantsEditDto
    {
        /// <summary>
        /// 自增ID
        /// </summary>
        [Display(Name = "自增ID")]
        public int Id { get; set; }

        /// <summary>
        /// 用户名
        /// </summary>
        public string? UserName { get; set; }

        /// <summary>
        /// 商户分类
        /// </summary>
        public string? CategoryTitle { get; set; }

        /// <summary>
        /// 店铺类型
        /// </summary>
        public string? StoreTitle { get; set; }

        /// <summary>
        /// 账户余额
        /// </summary>
        [Display(Name = "余额")]
        [Column(TypeName = "decimal(18, 2)")]
        public decimal Amount { get; set; } = 0;

        /// <summary>
        /// 不可用金额
        /// </summary>
        [Display(Name = "不可用金额")]
        [Column(TypeName = "decimal(18, 2)")]
        public decimal FrozenAmount { get; set; } = 0;

        /// <summary>
        /// 评论总数
        /// </summary>
        [Display(Name = "评论总数")]
        public int EvaluateCount { get; set; } = 0;

        /// <summary>
        /// 收藏人数
        /// </summary>
        [Display(Name = "收藏人数")]
        public int FavoriteCount { get; set; } = 0;

        /// <summary>
        /// 申请时间
        /// </summary>
        [Display(Name = "申请时间")]
        public DateTime AddTime { get; set; } = DateTime.Now;
    }

    /// <summary>
    /// 商户信息(编辑)
    /// </summary>
    public class MerchantsEditDto : MerchantsBaseDto
    {
        /// <summary>
        /// 所属用户ID
        /// </summary>
        [Display(Name = "所属用户")]
        [ForeignKey("ApplicatonUser")]
        public int UserId { get; set; }

        /// <summary>
        /// 交易费百分比
        /// </summary>
        [Display(Name = "交易费百分比")]
        public int? TradeFee { get; set; }

        /// <summary>
        /// 是否自营
        /// </summary>
        [Display(Name = "是否自营")]
        public byte IsSelf { get; set; } = 0;

        /// <summary>
        /// 是否推荐0否1是
        /// </summary>
        [Display(Name = "是否推荐")]
        public byte IsRecom { get; set; } = 0;

        /// <summary>
        /// 发布是否需审核
        /// </summary>
        [Display(Name = "发布审核")]
        public byte IsAudit { get; set; } = 1;

        /// <summary>
        /// 账户状态
        /// 0.正常
        /// 1.等待审核
        /// 2.审核失败
        /// </summary>
        [Display(Name = "账户状态")]
        public byte IsLock { get; set; } = 1;

        /// <summary>
        /// 排序数字
        /// </summary>
        [Display(Name = "排序数字")]
        public int SortId { get; set; } = 99;
    }

    /// <summary>
    /// 商户信息(基本)
    /// </summary>
    public class MerchantsBaseDto
    {
        /// <summary>
        /// 商户分类
        /// </summary>
        [Display(Name = "商户分类")]
        public int CategoryId { get; set; }

        /// <summary>
        /// 店铺类型
        /// </summary>
        [Display(Name = "店铺类型")]
        public int StoreId { get; set; }

        /// <summary>
        /// 店铺名称
        /// </summary>
        [Display(Name = "店铺名称")]
        [StringLength(128)]
        public string? Title { get; set; }

        /// <summary>
        /// 省份名称
        /// </summary>
        [Display(Name = "省份名称")]
        [StringLength(128)]
        public string? Province { get; set; }

        /// <summary>
        /// 城市名称
        /// </summary>
        [Display(Name = "城市名称")]
        [StringLength(128)]
        public string? City { get; set; }

        /// <summary>
        /// 区域名称
        /// </summary>
        [Display(Name = "区域名称")]
        [StringLength(128)]
        public string? Area { get; set; }

        /// <summary>
        /// 店铺地址
        /// </summary>
        [Display(Name = "店铺地址")]
        [StringLength(512)]
        public string? Address { get; set; }

        /// <summary>
        /// 手机号码
        /// </summary>
        [Display(Name = "手机号码")]
        [Required(ErrorMessage = "{0}不可为空")]
        [RegularExpression(@"^(13|14|15|16|18|19|17)\d{9}$")]
        public string? Mobile { get; set; }

        /// <summary>
        /// 商户头像
        /// </summary>
        [Display(Name = "商户头像")]
        [StringLength(512)]
        public string? Avatar { get; set; }

        /// <summary>
        /// 商户姓名
        /// </summary>
        [Display(Name = "商户姓名")]
        [StringLength(128)]
        public string? RealName { get; set; }

        /// <summary>
        /// 营业执照
        /// </summary>
        [Display(Name = "营业执照")]
        [StringLength(512)]
        public string? CertUrl { get; set; }

        /// <summary>
        /// 店铺简介
        /// </summary>
        [Display(Name = "店铺简介")]
        [StringLength(512)]
        public string? Intro { get; set; }
    }

    /// <summary>
    /// 商户信息(列表)
    /// </summary>
    public class MerchantsClientDto : MerchantsBaseDto
    {
        /// <summary>
        /// 自增ID
        /// </summary>
        [Display(Name = "自增ID")]
        public int Id { get; set; }

        /// <summary>
        /// 用户名
        /// </summary>
        public string? UserName { get; set; }

        /// <summary>
        /// 商户分类
        /// </summary>
        public string? CategoryTitle { get; set; }

        /// <summary>
        /// 店铺类型
        /// </summary>
        public string? StoreTitle { get; set; }

        /// <summary>
        /// 是否自营
        /// </summary>
        [Display(Name = "是否自营")]
        public byte IsSelf { get; set; } = 0;

        /// <summary>
        /// 评论总数
        /// </summary>
        [Display(Name = "评论总数")]
        public int EvaluateCount { get; set; } = 0;

        /// <summary>
        /// 收藏人数
        /// </summary>
        [Display(Name = "收藏人数")]
        public int FavoriteCount { get; set; } = 0;

        /// <summary>
        /// 申请时间
        /// </summary>
        [Display(Name = "申请时间")]
        public DateTime AddTime { get; set; } = DateTime.Now;
    }

    /// <summary>
    /// 商户信息(带商品)
    /// </summary>
    public class MerchantsGoodsClientDto
    {
        /// <summary>
        /// 自增ID
        /// </summary>
        [Display(Name = "自增ID")]
        public int Id { get; set; }

        /// <summary>
        /// 店铺名称
        /// </summary>
        [Display(Name = "店铺名称")]
        [StringLength(128)]
        public string? Title { get; set; }

        /// <summary>
        /// 商户头像
        /// </summary>
        [Display(Name = "商户头像")]
        [StringLength(512)]
        public string? Avatar { get; set; }

        /// <summary>
        /// 是否自营
        /// </summary>
        [Display(Name = "是否自营")]
        public byte IsSelf { get; set; } = 0;

        /// <summary>
        /// 收藏人数
        /// </summary>
        [Display(Name = "收藏人数")]
        public int FavoriteCount { get; set; } = 0;

        /// <summary>
        /// 商品列表
        /// </summary>
        public IEnumerable<ShopGoodsClientDto> ShopGoods { get; set; } = new List<ShopGoodsClientDto>();
    }
}
